package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import java.util.*;
import javax.persistence.Query;
import models.*;
import play.db.jpa.JPA;
import utils.*;

/**
 * Manage SupervisionLists related operations.
 */

public class SupervisionLists extends Controller {
  
    public static void index() {
        render();
    }

    /**
     * Get SupervisionLists json.
     */
    public static void json(int page, int pagesize) {    	
        List<SupervisionList> supervisionLists = SupervisionList.find("parentId is null order by OrderNum")
                                           .fetch(page, pagesize);         
        long total = SupervisionList.count("parentId is null");
        
    	
        String supervisionStr = SupervisionList.toJson(supervisionLists);
        String jsonStr = YUtils.ligerGridData(supervisionStr, total);
        renderJSON(jsonStr);
    }

    public static void simplejson() {
        List<SupervisionList> supervisionLists = SupervisionList.find("order by OrderNum").fetch();        
        renderJSON(SupervisionList.toSimpleJson(supervisionLists));
    }

    /**
     * Get SupervisionLists json.
     */
    public static void findAll() {
        List<SupervisionList> supervisionLists = SupervisionList.findAll();
        renderJSON(supervisionLists);
    }

    static User connectedUser() {
        String userId = session.get("logged");
        return (userId==null) ? null : (User)User.findById(Long.parseLong(userId));
    }

    /**
     * Add a SupervisionList.
     */
    public static void add(SupervisionList supervisionlist) {        
        
    }

    /**
     * Update a SupervisionList.
     */
    public static void save(SupervisionList supervisionlist) {       
        supervisionlist.save();
        renderJSON("");
    }
    
    /**
     * Delete a SupervisionList.
     */
    public static void delete(long id) {
        SupervisionList.findById(id)._delete();
        renderJSON("");
    }
  
}

